'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	const {loginName,loginPwd,phone,type} = event;
	
	//获取对应用户
	const {affectedDocs,data} = await db.collection("user")
	.aggregate()
	.match(type === "account" ? {loginName,loginPwd} : {phone})
	.end()
	
	
	//根据返回数据，返回数据给客户端
	if(affectedDocs === 0){
		return{
			code:1,
			msg:type === "account" ? "账号不存在或密码错误" : "手机号码未注册或验证码有误",
			data:null
		}
	}else{
		return {
		code:0,
		msg:"登录成功",
		data:data[0]
	}
	}
	
};
